home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / reversi.ml < prev    next >
Text File  |  1995-03-23  |  11KB  |  426 lines

  1. Article 2995 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!cs.utexas.edu!uunet!munnari.oz.au!brolga!uqcspe!batserver.cs.uq.oz.au!grue
  3. From: grue@batserver.cs.uq.oz.au (Frobozz)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Reversi for the HP48SX (Machine code version)
  6. Keywords: reversi
  7. Message-ID: <6479@uqcspe.cs.uq.oz.au>
  8. Date: 20 Dec 90 11:41:13 GMT
  9. Sender: news@uqcspe.cs.uq.oz.au
  10. Reply-To: grue@batserver.cs.uq.oz.au
  11. Organization: Computer Science Department, The University of Queensland, Brisbane, Australia
  12. Lines: 410
  13.  
  14. hiya,
  15.  
  16. Sorry, but the HP28 version isn't ready yet and it isn't going to be for
  17. several weeks at the minimum (my 28 is going on a holiday without me).
  18. Luckily, the 48 version is here.  Sorry if the following posting doesn't
  19. make all that much sense in places, I wrote it to be a join posting that
  20. included both versions of the program and I have cut it up quite a bit
  21. to make it for the 48 only.
  22.  
  23.  
  24.  
  25.     A new improved version of my old reversi program!  The main features
  26. of this version of the proram are:
  27.  
  28. * Features a true machine code move generator (including ALL searching and
  29.     position evalulation).
  30.  
  31. * And a machine code move checker.
  32.  
  33. These improvements mean that the program runs much faster than
  34. before and it responds to invalid moves much faster as well (especially
  35. when the invalid move is a pass).
  36.  
  37.  
  38. The user interface remains basically unchanged.  The biggest variation in
  39. this department is the renumber of the rows of the board to conform to
  40. normal reversi ordering (row 1 is now at the top!!).
  41.  
  42.  
  43. The game is started by pressing the PLAY softkey.  The board will be drawn
  44. and the player asked if they desire to go first (this question should be
  45. answered Y or N).  To enter a move, you should first type the column number
  46. 1 (left most) to 8 (right most) followed by the column number 1 (top) to
  47. 8 (bottom).  Your move will be made if it is legal.
  48. The other commands available are:
  49.  
  50. key | action
  51. ----+-----------------------------------------------
  52.  P  | Pass move (only allowed if no moves are legal)
  53.  Q  | Quit game
  54.  O  | Turn calculator off
  55.  U  | Take back last move (once only)
  56.  
  57. The input code will turn the calculator off if no key is pressed for a
  58. minute and pressing on will continue the game as if nothing had happened.
  59.  
  60. If anybody finds problems with this program or can think of improvements
  61. I'd like to hear about them.  I don't want to hear from people who think
  62. that the disply of moves is too slow, I made the making of moves slow on
  63. purpose (So that a player can see what effect a move really had while
  64. playing.  A move that just appears on the display is quite disconcerting
  65. to the player).
  66.  
  67. This version of the program doesn't play as well as the previous version
  68. (which is a bit of a pity since the older version played a good novice
  69. game).  This is mainly due to the very primative evalulation function
  70. which is used (it simply counts the number of disks each side has and
  71. maximises the difference).  I'm currently working on both improving the
  72. evalulation function and making the move generator search more than one
  73. ply ahead.  Both of these modifications will improve the play (I hope).
  74. The updated move selector should only require the replacement of the
  75. MVGEN routine (neat huh?).
  76.  
  77.  
  78. The usual disclaimers apply.  (i.e. the stuff about using undocumented
  79. features of the machine and any damage caused isn't my problem or fault).
  80. I'm also not responsible for this program causing memory losts.  I'll just
  81. say that I my calculator they don't cause them, your may be different.
  82.  
  83. The program is also copyright myself 1990, and it cannot be used for any
  84. commercial purpose without my permission.  Any NON-PROFIT usage is permitted
  85. without my prior approval.
  86.  
  87.  
  88. Enjoy...(full listing for HP48 is included at the end of this file).
  89. If enough interest is shown, I'll post the assembly source for the
  90. various routines.  (this source is commented quite well, but the comments
  91. haven't always kept up to date with the code [ it got modified quite a
  92. lot during its evolution] :-(
  93.  
  94.  
  95.                             Pauli
  96. seeya
  97.  
  98. Paul Dale               | Internet/CSnet:            grue@batserver.cs.uq.oz.au
  99. Dept of Computer Science| Bitnet:       grue%batserver.cs.uq.oz.au@uunet.uu.net
  100. Uni of Qld              | JANET:           grue%batserver.cs.uq.oz.au@uk.ac.ukc
  101. Australia, 4072         | EAN:                          grue@batserver.cs.uq.oz
  102.                         | UUCP:           uunet!munnari!batserver.cs.uq.oz!grue
  103. f4e6g4Qh4++             | JUNET:                     grue@batserver.cs.uq.oz.au
  104.  
  105. -----------------------------------------------------------------------------
  106.  
  107. Nice and simple for HP48 users out there, download the
  108. directory object (see below) and STO it (I use the name
  109. OTHL).  Enter the newly created directory and do the
  110. following:
  111.     INITP ASC-> 'INITP' STO
  112.     PUTN ASC-> 'PUTN' STO
  113.     GETN ASC-> 'GETN' STO
  114.     CKMOV ASC-> 'CKMOV' STO
  115.     MVGEN ASC-> 'MVGEN' STO
  116. You should now be able to press PLAY to play the game!
  117. You might want to type { PLAY } ORDER before running the game.
  118. [ Remember to make a backup copy of your memory before
  119.     you run the game, just in case! ]
  120.  
  121. The checksum for the directory is: F47h (using the BYTES
  122. command here folks).
  123. ---------------------------8<-----------------------------
  124. %%HP: T(3)A(R)F(.);
  125. DIR
  126.   PLAY
  127.     \<< SETUP
  128. "You first?" 4 DISS
  129.       WHILE GETK
  130. DUP 13 <
  131.       REPEAT DROP
  132.       END
  133.       IF 13 ==
  134.       THEN SWAPC
  135.       END
  136.       WHILE 1 FC?C
  137.       REPEAT BD 5
  138. R\->S GETN SWAP DROP
  139. 1 == 'PMOV' 'CMOV'
  140. IFTE SCOR
  141.         IF 8 FS?C
  142.         THEN
  143.           IF 2 FS?
  144.           THEN 1 SF
  145.           ELSE 2 SF
  146.           END
  147.         ELSE 2 CF
  148.           IF CCT
  149. PCT + 64 ==
  150.           THEN 1 SF
  151.           END
  152.         END
  153.       END
  154.       IF 3 FC?
  155.       THEN PCT CCT
  156. -
  157.         IF DUP 0 <
  158.         THEN
  159. "I win"
  160.         ELSE
  161.           IF DUP 0
  162. >
  163.           THEN
  164. "You win"
  165.           ELSE
  166. "Draw"
  167.           END
  168.         END 1 DISS
  169. ABS "by " SWAP \->STR
  170. + " disks" + 4 DISS
  171.       END CLEAN
  172.     \>>
  173.   CLEAN
  174.     \<< { PCT CCT BD
  175. OLDP } PURGE STOF 7
  176. FREEZE
  177.     \>>
  178.   SETUP
  179.     \<< RCLF 1 9
  180.       FOR j j CF
  181.       NEXT 2 DUP
  182. 'PCT' STO 'CCT' STO
  183. INITP NEWOB 'BD'
  184. STO { } 'OLDP' STO
  185. PICT PURGE { # 0h
  186. # 0h } PVIEW 1 8
  187.       FOR j PICT
  188. # 60h j 6 * R\->B 2
  189. \->LIST j 1 \->GROB GOR
  190.       NEXT PICT {
  191. # 64h # 0h }
  192. "12345678" 1 \->GROB
  193. GOR 4 4 1 DRWP 4 5
  194. -1 DRWP 5 4 -1 DRWP
  195. 5 5 1 DRWP
  196.     \>>
  197.   SCOR
  198.     \<< "  My total "
  199. CCT \->STR + 2 DISS
  200. "Your total " PCT
  201. \->STR + 3 DISS
  202.     \>>
  203.   INITP
  204. "C2A205E00066000F0000088888888880000000080000000080000000080001F0
  205. 008000F1000800000000800000000800000000888888888851C145B571A172E2
  206. 24946595819103739304758512221363A3F3E4F4023282D23484D40561B1E152
  207. B42555A592C24474A2B22353B3E35464F142C41500FA22"
  208.   SWAPC
  209.     \<< 5 R\->S BD OVER
  210. GETN NEG ROT SWAP
  211. PUTN DROP
  212.     \>>
  213.   FLIPS
  214.     \<< \-> x y
  215.       \<< PICT x 4 *
  216. # 60h + y 6 * R\->B 2
  217. \->LIST
  218. GROB 4 6 707020500000
  219. GXOR
  220.       \>>
  221.     \>>
  222.   DRWP
  223.     \<< \-> x y c
  224.       \<< PICT x 4 *
  225. # 60h + y 6 * R\->B 2
  226. \->LIST c 1 ==
  227. GROB 4 6 705050700000
  228. GROB 4 6 002070200000
  229. IFTE REPL
  230.       \>>
  231.     \>>
  232.   MKMOV
  233.     \<< BD 5 R\->S GETN
  234. \-> x y j c
  235.       \<< BD x y XY\->S
  236. c PUTN x y c DRWP 1
  237.         IF c -1 ==
  238.         THEN 'CCT'
  239.         ELSE 'PCT'
  240.         END STO+ -1
  241. 1
  242.         FOR a -1 1
  243.           FOR b 1
  244. 'j' STO
  245.             WHILE x
  246. a j * + y b j * +
  247. XY\->S GETN c NEG ==
  248.             REPEAT
  249. 1 j + 'j' STO
  250.             END
  251.             IF x a
  252. j * + y b j * +
  253. XY\->S GETN c ==
  254.             THEN
  255.               DO j
  256. 1 - 'j' STO
  257. IF x a j * + y b j
  258. * + XY\->S SWAP OVER
  259. GETN c NEG ==
  260. THEN SWAP c PUTN x
  261. a j * + y b j * +
  262. FLIPS 'PCT' 'CCT'
  263.   IF c -1 ==
  264.   THEN SWAP
  265.   END -1 STO+ 1
  266. STO+
  267. ELSE SWAP DROP 7 SF
  268. END
  269.               UNTIL
  270. 7 FS?C
  271.               END
  272.             END
  273.           NEXT
  274.         NEXT DROP
  275.       \>> SWAPC
  276.     \>>
  277.   PUTN
  278. "CCD2065000147108174E78F1466013706135147C2135179110349C2A28A29030
  279. F660030115D007135142164808C6DE5"
  280.   GETN
  281. "CCD2056000137061358F14660147C2135179D015B030F902D2D6C4C4C2C4C4CA
  282. 344B2A2CA07135141CF142164808CD0808212D69DF1A9E"
  283.   CMOV
  284.     \<< "Thinking..."
  285. 4 DISS BD NEWOB DUP
  286. NEWOB MVGEN S\->XY
  287.       IF DUP 0 <
  288.       THEN DROP2
  289. "I pass" 1 DISS
  290. SWAPC 8 SF
  291.       ELSE DUP2 R\->C
  292. \->STR "My move "
  293. SWAP + 1 DISS MKMOV
  294.       END
  295.     \>>
  296.   DISS
  297.     \<< PICT SWAP
  298. # Ah * # 10h + # 0h
  299. SWAP 2 \->LIST ROT
  300. # 60h # Ah BLANK {
  301. # 0h # 0h } ROT 2
  302. \->GROB GOR REPL
  303.     \>>
  304.   PMOV
  305.     \<< 0 DUP \-> c1 c2
  306.       \<< "Your move"
  307. 4 DISS
  308.         WHILE 4
  309. FC?C
  310.         REPEAT GETK
  311. 'c1' STO
  312.           IF c1
  313.           THEN
  314.             IF c1 8
  315. >
  316.             THEN 5
  317. SF { OFF
  318.               \<<
  319. IF BD 0 R\->S CKMOV
  320. THEN 4 SF 8 SF
  321. SWAPC
  322. ELSE 5 CF
  323. END
  324.               \>>
  325.               \<< 1 3
  326. 4 6 SF SF SF SF
  327.               \>>
  328.               \<<
  329. OLDP SIZE 4 ==
  330. \<< OLDP LIST\-> DROP
  331. PICT { # 0h # 0h }
  332. ROT REPL 'BD' STO
  333. 'PCT' STO 'CCT' STO
  334. { } 'OLDP' STO
  335. \>>
  336. \<< 5 CF
  337. \>> IFTE
  338.               \>>
  339.               \<< 5
  340. CF
  341.               \>>
  342.               \<< 5
  343. CF
  344.               \>> }
  345. c1 8 - GET EVAL
  346.             ELSE c1
  347. \->STR 1 DISS GETK
  348. 'c2' STO c1 \->STR c2
  349. \->STR + 1 DISS
  350.               IF BD
  351. c1 c2 XY\->S CKMOV
  352.               THEN
  353. 4 SF CCT PCT BD
  354. NEWOB PICT RCL 4
  355. \->LIST 'OLDP' STO c1
  356. c2 MKMOV
  357.               END
  358.             END
  359.           END
  360.           IF 4 FC?
  361. 5 FC?C AND
  362.           THEN
  363. "Illegal" 1 DISS
  364. ERRBELL
  365.           END
  366.         END
  367.       \>>
  368.     \>>
  369.   S\->XY
  370.     \<< S\->R 11 - DUP
  371. 9 MOD SWAP 9 / IP
  372.     \>>
  373.   XY\->S
  374.     \<< 9 * + 11 +
  375. R\->S
  376.     \>>
  377.   GETK
  378.     \<< TICKS \-> sttme
  379.       \<<
  380.         DO
  381.           IF TICKS
  382. sttme - B\->R 491520
  383. >
  384.           THEN OFF
  385. TICKS 'sttme' STO
  386.           END
  387.         UNTIL KEY
  388.         END
  389.       \>> KMAP SWAP
  390. POS
  391.     \>>
  392.   KMAP { 82 83 84
  393. 72 73 74 62 63 33
  394. 34 35 43 52 32 }
  395.   R\->S
  396.     \<< # 18CEAh
  397. SYSEVAL
  398.     \>>
  399.   S\->R
  400.     \<< # 18DBFh
  401. SYSEVAL
  402.     \>>
  403.   CKMOV
  404. "CCD20451008F146608FB9760D20B0614713517EC213416915F0B0690A508528A
  405. C0316A169D23184D715E090EB07150871D2160CF8AF6E651015E090E61713086
  406. 1D0349C2A26A00344B2A2DA8F2D760141070A142164808CD2CE7040D23087730
  407. D23097E20D230A7520D2E67D10348FFFF7210347FFFF7700346FFFFD5132130C
  408. 013115F0862B0E690AB001CE90E00C013115F090A0080820890200133862F0E6
  409. 90AADCE6C00CE90ADCE6851013B92"
  410.   MVGEN
  411. "CCD20A5200179E7E78FB97601C9D20B067090070A8F73560142164808CD51321
  412. 30C013115F0862B0E690AB001CE90E00C013115F090A0080820890200133862F
  413. 0E690AADCE6C00CE90ADCE6851F9C013115B09080015D01336AEF13713513417
  414. 414213016913610B14313117913710A74408AAB27E21AF41011321007B208AA9
  415. 175111119F8DE6EDFD21080111011BFACA1000111A13411B1351567D72580820
  416. F902508522687B2125B8A2034660002D155716F17F152715170D880DE11BCBE7
  417. E7134D014A968B611BCA130156090EBD841D2CE7F8ED2308768ED23097D7ED23
  418. 0A747ED2E67C6E348FFFF716E347FFFF765E346FFFF7B4E861786900D2641030
  419. F8625030115C0DB1121311450111313117A179D23184D73104AF1D515B030F90
  420. 601E5170CF8AFAE01301906EECD69EF1614"
  421. END
  422. ---------------------------8<-----------------------------
  423. --
  424.  
  425.  
  426.